﻿using System;
using System.IO;
using System.Windows.Forms;

namespace Zove.Desktop {
    public partial class OpenWorkspaceWindow : Form {
        public OpenWorkspaceWindow() {
            InitializeComponent();
        }

        public string SelectedPath {
            get {
                return this.tbWorkspace.Text;
            }
        }

        private void button1_Click(object sender, EventArgs e) {
            FolderBrowserDialog d = new FolderBrowserDialog();

            d.Description = "Select a folder to open";
            d.ShowNewFolderButton = true;
            if (d.ShowDialog() == DialogResult.OK) {
                this.tbWorkspace.Text = d.SelectedPath;
            }
        }

        private void btnOk_Click(object sender, EventArgs e) {
            if (!Directory.Exists(this.tbWorkspace.Text)) {
                MessageBox.Show("The directory does not exist.");

                return;
            }

            if (this.checkBox1.Checked) {
                DesktopUtils.DefaultWorkspace = this.tbWorkspace.Text;
            }
            if (this.checkBox2.Checked) {
                DesktopFormContext.Context.Main.WorkspaceWindowCollection.CloseAll();
            }

            DesktopUtils.Workspaces += this.tbWorkspace.Text;
            this.DialogResult = DialogResult.OK;
            this.Close();
        }
    }
}
